/*
 * Copyright (C) 2017 ~ 2025 the original author or authors.
 * <James Wong@gmail.com, 983708408@qq.com> Technology CO.LTD.
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Reference to website: http://wl4g.com
 */
package com.wl4g.infra.integration.example.web;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wl4g.infra.common.web.rest.RespBase;
import com.wl4g.infra.context.page.PageHolder;
import com.wl4g.infra.context.web.BaseController;
import com.wl4g.infra.integration.feign.springcloud.example.bean.OrderInfo;
import com.wl4g.infra.integration.feign.springcloud.example.service.OrderService;

/**
 * {@link OrderController}
 * 
 * @author James Wong &lt;jameswong1376@gmail.com&gt;
 * @version v1.0 2021-03-18
 * @sine v1.0
 * @see
 */
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {

    private @Autowired OrderService orderService;

    @RequestMapping(value = "/list", method = GET)
    public RespBase<?> list(PageHolder<OrderInfo> page,
            @RequestParam(name = "orderName", defaultValue = "", required = false) String orderName) {
        RespBase<Object> resp = RespBase.create();

        resp.setData(orderService.list(page, orderName));
        log.info("find orders resp: {}", resp);
        return resp;
    }

    @RequestMapping(value = "/create", method = POST)
    public RespBase<?> create(@RequestBody OrderInfo order,
            @RequestParam(name = "goodsId", defaultValue = "20001", required = false) Long goodsId) {
        log.info("Saving order, orderId: {}", order.getId());
        RespBase<Object> resp = RespBase.create();

        orderService.create(order, goodsId);
        log.info("Created orders resp: {}", resp);
        return resp;
    }

}
